<?php

require_once 'config/config.php';

class db {

    static $connection;

    public function connect() {
        if (!isset(self::$connection)) {
            self::$connection = mysql_connect(DB_HOST . ":" . DB_PORT, DB_USER, DB_PASS) or die(mysql_error());
            mysql_select_db(DB_NAME, self::$connection);
            mysql_query("SET NAMES utf8", self::$connection);
        } else {
            return self::$connection;
        }
    }

    public function query($query) {
        $datas = array();
        mysql_query("SET NAMES utf8", self::$connection);
        $query = mysql_query($query, self::$connection);
        while ($row = mysql_fetch_assoc($query))
            $datas[] = $row;
        return $datas;
    }

}

?>